//
//  OrderSuccessViewController.m
//  XDBaseFrameWork
//
//  Created by xindao on 14-9-24.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "OrderSuccessViewController.h"

@interface OrderSuccessViewController ()

@end

@implementation OrderSuccessViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.leftBtn.hidden = YES;


    if (![_type isEqualToString:@"chooseImage"]) {
        self.titleLabel.text = @"预约成功";
    }else{
        self.titleLabel.text = @"选片成功";
    }

    [self createViews];


}

- (void)createViews{
    if (![_type isEqualToString:@"chooseImage"]){
        self.contentView.backgroundColor = UIColorFromRGB(0xedeae9);
        UIImageView * ivv = [UIImageView initImageViewRect:CGRectMake((UI_SCREEN_WIDTH-177)/2.0f,57/2.0f,177,33) andImage:LOADIMAGE(@"successorder_img1@2x") andUserInteractionEnabled:YES];
        [self.contentView addSubview:ivv];
        
        UIImageView *hvv = [UIImageView initImageViewRect:CGRectMake((UI_SCREEN_WIDTH-290/2.0f)/2.0f,height_y(ivv)+30, 290/2.0f, 290/2.0f) andImage:LOADIMAGE(@"successorder_img2@2x") andUserInteractionEnabled:YES];
        [self.contentView addSubview:hvv];
        
        
        UIImageView * headerIV = [[UIImageView alloc] initWithFrame:CGRectMake(hvv.frame.origin.x+10, hvv.frame.origin.y+9, 246/2.0f,246/2.0f)];
        headerIV.backgroundColor = UIColorFromRGB(0xeaeaea);
        headerIV.layer.masksToBounds = YES;
        headerIV.layer.cornerRadius = 246/4.0f;
        [headerIV sd_setImageWithURL:[NSURL URLWithString:[XDTools sharedXDTools].emplImgUrl] placeholderImage:nil];
        [self.contentView addSubview:headerIV];
        
        UILabel * nameLB = [UILabel initLabelText:[XDTools sharedXDTools].emplName andRect:CGRectMake(0, height_y(headerIV)+10, UI_SCREEN_WIDTH, 25) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:20] andTextColor:UIColorFromRGB(0x8b8b8b) andTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:nameLB];
        
        UILabel * levelLB = [UILabel initLabelText:[XDTools sharedXDTools].emplLevel andRect:CGRectMake(0, height_y(nameLB)+2, UI_SCREEN_WIDTH, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:UIColorFromRGB(0x929292) andTextAlignment:NSTextAlignmentCenter];
        levelLB.attributedText = [XDTools getAcolorfulStringWithTextArray:@[@"A"] Color:RGBA(255, 42, 0, 1) Font:[UIFont systemFontOfSize:16] AllText:levelLB.text];
        [self.contentView addSubview:levelLB];
        
        UILabel * lb = [UILabel initLabelText:@"期待为您的天使拍照！" andRect:CGRectMake(0,height_y(levelLB)+23+15,UI_SCREEN_WIDTH, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:UIColorFromRGB(0xff6800) andTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:lb];
    
        UIButton * orangeBtn = [UIButton initButton:CGRectMake(44,self.contentView.frame.size.height-33-31.5, 110,31.5) btnNorImage:[UIImage imageNamed:@"successorder_img3"] btnHighlightImage:[UIImage imageNamed:@"successorder_img3"] btnTitle:@"查看订单" titleColor:[UIColor whiteColor] titleFont:[UIFont systemFontOfSize:18]];
        orangeBtn.tag = 918280;
        [orangeBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:orangeBtn];
        
        UIButton * greenBtn = [UIButton initButton:CGRectMake(width_x(orangeBtn)+18,orangeBtn.frame.origin.y, 110, 31.5) btnNorImage:[UIImage imageNamed:@"successorder_img4"] btnHighlightImage:[UIImage imageNamed:@"successorder_img4"] btnTitle:@"返回首页" titleColor:[UIColor whiteColor] titleFont:[UIFont systemFontOfSize:18]];
        greenBtn.tag = 918281;
        [greenBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:greenBtn];
        
        if(iPhone5){

        }else{
            lb.frame = CGRectMake(0,height_y(levelLB)+23+5,UI_SCREEN_WIDTH, 20);
            orangeBtn.frame  =CGRectMake(44, self.contentView.frame.size.height-23-31.5, 110, 31.5);
            greenBtn.frame = CGRectMake(width_x(orangeBtn)+18,orangeBtn.frame.origin.y, 110, 31.5);
        }
        
        return;
    }

    
    
    
    UIImageView * iv = [[UIImageView alloc] initWithFrame:CGRectMake(70, 55, 25, 25)];
    iv.image = [UIImage imageNamed:@"orderSuccess"];
    [self.contentView addSubview:iv];

    UILabel * label = [UILabel initLabelText:@"摄影师预约成功！" andRect:CGRectMake(VIEW_POINT_MAX_X(iv)+10,55,150,25) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:UIColorFromRGB(0x453d35) andTextAlignment:NSTextAlignmentLeft];
    if ([_type isEqualToString:@"chooseImage"]) {
        label.text = @"选片完成!";
        label.font = [UIFont boldSystemFontOfSize:18];
        iv.frame = CGRectMake(90, 55, 25, 25);
        label.frame = CGRectMake(VIEW_POINT_MAX_X(iv)+10,55,150,25);

    }
    [self.contentView addSubview:label];

    float h = 0;

    if ([_type isEqualToString:@"chooseImage"]) {
        self.titleLabel.text = @"选片完成";

        UIView * bgView = [UIView initViewRect:CGRectMake(20, height_y(label)+40, UI_SCREEN_WIDTH-40, 130) andBackGroudColor:UIColorFromRGB(0xeaeaea)];
        bgView.layer.masksToBounds = YES;
        bgView.layer.cornerRadius = 3;
        [self.contentView addSubview:bgView];

        UILabel * lb = [UILabel initLabelText:@"您的相册，我们将于3个工作日内寄出;\n\n底片原图，我们将于1个工作日内发送百度云的下载链接给您，您可以在订单详情页面查看。" andRect:CGRectMake(10,10,UI_SCREEN_WIDTH-60,110) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:15] andTextColor:UIColorFromRGB(0x453d35) andTextAlignment:NSTextAlignmentLeft];
        lb.numberOfLines = 0;
        [bgView addSubview:lb];

        h = height_y(bgView);

    }else{
        UIImageView * headerIV = [[UIImageView alloc] initWithFrame:CGRectMake((UI_SCREEN_WIDTH-60)/2, height_y(label)+25, 60, 60)];
        headerIV.backgroundColor = UIColorFromRGB(0xeaeaea);
        headerIV.layer.masksToBounds = YES;
        headerIV.layer.cornerRadius = 30;
        [headerIV sd_setImageWithURL:[NSURL URLWithString:[XDTools sharedXDTools].emplImgUrl] placeholderImage:nil];
        [self.contentView addSubview:headerIV];

        UILabel * nameLB = [UILabel initLabelText:[XDTools sharedXDTools].emplName andRect:CGRectMake(0, height_y(headerIV)+8, UI_SCREEN_WIDTH, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:RGBA(48, 44, 39, 1) andTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:nameLB];

        UILabel * levelLB = [UILabel initLabelText:[XDTools sharedXDTools].emplLevel andRect:CGRectMake(0, height_y(nameLB)+3, UI_SCREEN_WIDTH, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:RGBA(112,98,85, 1) andTextAlignment:NSTextAlignmentCenter];
        levelLB.attributedText = [XDTools getAcolorfulStringWithTextArray:@[@"A"] Color:RGBA(255, 42, 0, 1) Font:[UIFont systemFontOfSize:16] AllText:levelLB.text];
        [self.contentView addSubview:levelLB];

        UILabel * lb = [UILabel initLabelText:@"期待上门为您的天使拍照！" andRect:CGRectMake(0,height_y(levelLB)+23,UI_SCREEN_WIDTH, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:RGBA(48, 44, 39, 1) andTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:lb];

        h = height_y(lb);
    }

    UIButton * orangeBtn = [UIButton initButton:CGRectMake(40, h+35, 110, 40) btnNorImage:[UIImage imageNamed:@"orangeBtn"] btnHighlightImage:[UIImage imageNamed:@"orangeBtn"] btnTitle:@"查看订单" titleColor:[UIColor whiteColor] titleFont:[UIFont systemFontOfSize:18]];
    orangeBtn.tag = 918280;
    [orangeBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:orangeBtn];

    UIButton * greenBtn = [UIButton initButton:CGRectMake(VIEW_POINT_MAX_X(orangeBtn)+20, h+35, 110, 40) btnNorImage:[UIImage imageNamed:@"darkGreenBtn"] btnHighlightImage:[UIImage imageNamed:@"darkGreenBtn"] btnTitle:@"返回首页" titleColor:[UIColor whiteColor] titleFont:[UIFont systemFontOfSize:18]];
    greenBtn.tag = 918281;
    [greenBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:greenBtn];
}

- (void)btnClick:(UIButton *)sender{
    if (sender.tag == 918280) {
        //查看订单
        [[NSUserDefaults standardUserDefaults]setObject:@"1" forKey:@"isBackToOrderListToRefresh"];
        XDTabBarViewController * tabBar = self.navigationController.viewControllers.firstObject;
        [tabBar confirmSelectTabBar:1];
        [tabBar setSelectedIndex:1];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else{
        //返回首页
    
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
